#include <iostream>
#include <string>

#include "jsoncpp/json/json.h"

int main()
{
    // 创建Json对象
    // Json::Value 万能的类型
    Json::Value root;

    // 添加kv映射数据
    root["k1"] = 100;
    root["k2"] = 100;
    root["hello"] = "world";
    root["bit"] = 8;

    // 序列化
    Json::FastWriter writer;
    std::string s = writer.write(root);
    std::cout << s << std::endl;

    // 反序列化
    int k1, k2, bit;
    std::string hello;
    Json::Value _root;
    Json::Reader reader;
    if (reader.parse(s, _root))
    {
        k1 = _root["k1"].asInt();
        k2 = _root["k2"].asInt();
        hello = _root["hello"].asCString();
        bit = _root["bit"].asInt();
    }

    std::cout << k1 << " " << k2 << " " << hello << " " << bit << std::endl;
    return 0;
}